﻿#ifndef PST_GRAPH2D_H
#define PST_GRAPH2D_H

#include <QWidget>
#include <QList>
#include <QHash>
#include <QPair>
#include "InfomationCurve2DBasical.h"
class QCPGraph;
class QStandardItem;

namespace pst
{
    class Graph2DSettings;
    class SelectDatatDialog;
    class Curve2DPlotor;
    /// @brief 二维图形
    class Graph2D : public QWidget
    {
        Q_OBJECT
    public:
        explicit Graph2D(QWidget* parent = 0);
        ~Graph2D();

        void addLine(const QPair<QString, QVector<double>>& x,
            const QPair<QString, QVector<double>>& y);

        QCPGraph* addLine(const InfomationCurve2DBasical& info);//传引用，改数据
        bool saveScreenShot(const QString& path);

        inline Graph2DSettings* getSettings() const { return m_settings; }
        inline Curve2DPlotor* getPlotor() const { return m_customPlot; }
        inline const QHash<QStandardItem*, InfomationCurve2DBasical>& getCurve() const { return m_curveMap; }

    signals:
        void signal_generateANewGraphCurve(QList<InfomationCurve2DBasical>& infos);


    public slots:
        void slot_generateANewGraphCurve(const QList<QStandardItem*>& itemList,
            const InfomationCurve2DBasical& changedInfo);
        void slot_chosenItemsChanged(const QList<QStandardItem*>& itemList);
        void slot_updateCurveData(const QList<QStandardItem*>& itemList,
            const InfomationCurve2DBasical& changedInfo);

        void slot_legendTitleFontFamilyChanged(const QString& fontFamily);
        void slot_legendTitleFontSizeChanged(int fontSize);

        void slot_showHideCurve(const QPair<int, bool>& curveState);
    private:
        void initConnections();
        void updateCurve(QStandardItem* item, InfomationCurve2DBasical& info);

    private:
        Curve2DPlotor* m_customPlot{ nullptr };
        /// @brief 二维图形设置
        Graph2DSettings* m_settings{ nullptr };
        //SelectDatatDialog* m_selecetDataDialog;

        QList<QCPGraph*> m_graphs; ///QCPGraph

        QList<QColor> m_colorList;

        //存放设置曲线列表中的曲线和对应的曲线信息，用于从设置栏曲线中重新找回曲线信息
        QHash<QStandardItem*, InfomationCurve2DBasical> m_curveMap;
    };
}

#endif // PST_GRAPH2D_H
